<?php 

class base_player{

	var $name;
	var $acc_name;
	var $k;
	var $d;
	var $c;
	var $g;
	var $r; /* returns */
	var $w; /* Weapons array */
	public $tp;
	var $kdr;
	var $cgr;
	var $ckr;
	/* misc */
	var $t; /* tier */
    public $p_id; /* NOTE this player id DOES NOT MATCH the one in soldat, they work completely different */
	var $ip;
	var $maps;
	var $wins;
	var $minutes;
	var $rank;
	var $points;
	var $spot; /* ingame spot */
	var $mlt; /* mltiple kill array */
	
	/* Timers */
	public $kill_timer;
	public $kill_count;
	
	public $cap_timer;
	public $ct;
	
	public $hold_timer;
	public $hold_time;
	
	public $team; /* 0 = Alpha , 1 = Bravo */
	
    public $map_timer; /* Time Played in current Map */
    
	var $flag; 
	
	public $is_rated; /* boolean; 200 kills 20 caps */
	public $active; /* WIP */
	
	public $alive_time;
	public $alive_timer;
	
	public $wstreak;
	public $plus_minus;
    
	public $u_id;

    public $dominated;
    
    /* Rank variables */
    public $mu;
    public $sigma;
    public $rating;
    
	public function __construct( $record = null,  $name = 'Soldier'){

		/* Available database records make all other jobs allot easier */
		$this->minutes = time();
		
		$this->mlt = array();
		
		$this->mlt[0] = 0;
		
		if( $record ){
		
			$this->acc_name = $record['name'];
			$this->name = $name;
			$this->k = $record['kills'];
			$this->d = $record['deaths'];
			$this->c = $record['caps'];
			$this->g = $record['grabs'];
			$this->r = $record['returns'];
			$this->t = $record['tier'];
			$this->maps = $record['maps'];
			$this->wins = $record['wins'];
			$this->kdr = $record['kd'];
			$this->cgr = $record['cg'];
			$this->tp = $record['time_played'];
			$this->points = $record['points'];
			
			$this->ip = $record['ip'];
			
			$this->mlt[1] = $record['doubles'];
			$this->mlt[2] = $record['triples'];
			$this->mlt[3] = $record['multi'];
			
			$this->alive_time = $record['life_span'];
			$this->wstreak = $record['streak'];
			
			$this->kill_count = 0;
			
            $this->plus_minus = $record['plusminus'];
            
            /* Rank variables */
            $this->mu = $record['mu'];
            $this->sigma = $record['sigma'];
            $this->rating = $record['rating'];
            
			if( $this->c >= 20 && $this->k >= 200 )
				$this->is_rated = true;
			/* DBG only */ $this->is_rated = true;
		}else{
		
			$this->name = $name;
			$this->acc_name = 'invalid_account_name';
			$this->k = 0;
			$this->d = 0;
			$this->c = 0;
			$this->g = 0;
			$this->r = 0;
			$this->t = 0;
			$this->mlt[1] = 0;
			$this->mlt[2] = 0;
			$this->mlt[3] = 0;
			$this->kdr = 0;
			$this->cgr = 0;
			$this->tp = 0;
			//$this->points = 0;
			$this->ip = "localhost";
			$this->kill_count = 0;
			$this->maps = 0;
			$this->wins = 0;
		}
		
		$this->kill_timer = $this->minutes; /* This is sorta important */
		$this->alive_timer = $this->minutes;
        $this->map_timer = $this->minutes;
        
		$this->flag = 0;
		
        /* In game dominations */
        $this->dominated = array();
        for( $i = 0; $i < 33; $i++ )
            $this->dominated[$i] = 0;
         
		/* Personal Weapon Stats are never fetched */
		$this->w = array(
			'Desert Eagles' => 0,
			'HK MP5' => 0,
			'Ak-74' => 0,
			'Steyr AUG' => 0,
			'Spas-12' => 0,
			'Ruger 77' => 0,
			'M79' => 0,
			'Barrett M82A1' => 0,
			'FN Minimi' => 0,
			'XM214 Minigun' => 0,
			'Selfkill' => 0,
			'Combat Knife' => 0,
			'Chainsaw' => 0,
			'LAW' => 0,
			'Grenade' => 0 
		);
		
	}
	
	/* Update Functions */
	public function update_kills($weapon){
		if( isset($weapon) ){			
			$this->k++;
			$this->w[$weapon]++;
		}
	}
	
	public function update_kdr(){
		if( $this->k ){
			if( $this->d ){
				$this->kdr = $this->k / $this->d ;
				$this->kdr = round($this->kdr, 2);
			}else{
				$this->kdr = $this->k;
			}
		}else{
			if( $this->d ){
				$this->kdr = 0.001; /* As soon as the player gets a kill this is set to a proper value */
			}else{
				$this->kdr = 0;
			}
		}
	}
	
	public function update_cgr(){
		if( $this->c ){
				$this->cgr = $this->c / $this->g ;
		}else{
			if( $this->g ){
				$this->cgr = 0.001; /* As soon as the player gets a cap this is set to a proper value */
			}else{
				$this->cgr = 0;
			}
		}
		$this->cgr = round($this->cgr, 2);
	}
	
	public function update_ckr(){
		if( $this->c ){
			if( $this->k ){
				$this->ckr = $this->c / $this->k ;
			}else{
				$this->ckr = $this->c ;
			}
		}else{
			if( $this->k ){
				$this->ckr = 0.001; 
			}else{
				$this->ckr = 0;
			}
		}
		$this->ckr = round($this->ckr, 2);
	}
	
	public function update_time_played(){
		$this->tp += round( ((time() - $this->minutes)/60) , 0 );
		$this->minutes = time();
	}
	
	
}



?>
